package com.system.controller;


import com.system.po.info.Information;
import com.system.service.InformationService;
import com.system.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@RequestMapping("Information")
@Controller
@Api(description = "事故信息接口")
public class InformationController {

    @Autowired
    private InformationService InformationServiceImpl;


    @RequestMapping(value = "addInformation",method = RequestMethod.POST)
    @ApiOperation("添加事故信息")
    @ResponseBody
    public Result addInformation(@RequestBody Information information){
     boolean add=   InformationServiceImpl.addInformation(information);
        return  add?Result.ok("添加成功"):Result.fail("添加失败");
    }



    @RequestMapping(value = "addInformationAndReturnId",method = RequestMethod.POST)
    @ApiOperation("添加事故信息并返回主键id")
    @ResponseBody
    public Result addInformationAndReturnId(@RequestBody Information information){
        Information information1=   InformationServiceImpl.addInformationAndReturnId(information);
        return  information1!=null?Result.ok(information1):Result.fail("添加失败");
    }



    @RequestMapping(value = "updateInformation",method = RequestMethod.PUT)
    @ApiOperation("修改事故信息")
    @ResponseBody
    public Result updateInformation(@RequestBody Information information){
        boolean update=   InformationServiceImpl.updateInformation(information);
        return  update?Result.ok("修改成功"):Result.fail("修改失败");
    }


    @RequestMapping(value = "selectInformationById/{id}",method = RequestMethod.GET)
    @ApiOperation("修改事故信息")
    @ResponseBody
    public Result selectInformationById(@PathVariable("id") Integer id){
        Information information=   InformationServiceImpl.selectInformationById(id);
        return  information!=null?Result.ok(information):Result.fail("查询失败");
    }

}
